import * as _api from '@/api/system/lookup'

const state = {}

const mutations = {}

const _handler = function(_api_method, params) {
  return new Promise((resolve, reject) => {
    _api_method(params).then(data => {
      resolve(data)
    }).catch(error => {
      reject(error)
    })
  })
}

const actions = {
  // list
  list({ commit, state }, params) {
    return _handler(_api.list, params)
  },
  // page
  page({ commit, state }, params) {
    return _handler(_api.page, params)
  },
  // get
  get({ commit, state }, params) {
    return _handler(_api.get, params)
  },
  // add
  add({ commit, state }, params) {
    return _handler(_api.add, params)
  },
  // edit
  edit({ commit, state }, params) {
    return _handler(_api.edit, params)
  },
  // remove
  remove({ commit, state }, params) {
    return _handler(_api.remove, params)
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
